package com.qingke.hibernate;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import com.qingke.hibernate.bean.Student;

public class RestrictionDemo {
	public static void main(String[] args){
		SessionFactory sf=new Configuration().configure().buildSessionFactory();
		Session session=sf.openSession();
		
		DetachedCriteria detachedCriteria=DetachedCriteria.forClass(Student.class);
		
		Criteria criteria=detachedCriteria.getExecutableCriteria(session);
		
		Map<String,Object> pra=new HashMap<>();
		pra.put("gender", "Ů");
		
//		criteria.add(Restrictions.eq("gender", "Ů"));
//		criteria.add(Restrictions.allEq(pra));
		
//		criteria.add(Restrictions.like("email","%lzslhm%"));
		
//		criteria.add(Restrictions.and(Restrictions.like("email","%lzslhm%"),Restrictions.eq("gender", "Ů")));
//		criteria.add(Restrictions.or(Restrictions.like("email","%lzslhm%"),Restrictions.eq("gender", "Ů")));
		
//		criteria.add(Restrictions.between("age", 21,30));
		
		Collection<Integer> collection=new ArrayList<>();
		collection.add(19);
		collection.add(27);
		criteria.add(Restrictions.in("age", collection));
		
		
		
		List<?> students=criteria.list();
		for(Object o:students){
			System.out.println(o);
		}
		
		session.clear();
		
		students=criteria.list();
		for(Object o:students){
			System.out.println(o);
		}
		
	}
}	
